use ClientDW_A
var templates = [];
db.IndicatorTemplate.find().forEach(function(item){
   templates.push({Number: item.Number, Category: item.IndicatorCategory}); 
});
use ClientPlatform

db.CriteriaLevel3.update({}, { $set: { Category: "None" }}, { upsert: false, multi: true})
var numbers = [];
db.CriteriaLevel3.find().forEach(function(item){
    var index = item.Name.indexOf(" ");
    var isIndicator = false;    
    if (index > 3 && (item.Name.startsWith('E.') || item.Name.startsWith('S.') || item.Name.startsWith('G.')))
        isIndicator = true;   
    if (!isIndicator)
        return;
    numbers.push({Id: item._id, Category: item.Category, Number: item.Name.substring(0, index)});
});

var criterias = [];
numbers.forEach(function(item){
    
    var category = '';
    
    for (var i = 0; i < templates.length; i++)
    {
        var template = templates[i];
        if (template.Number == item.Number)
        {
            category = template.Category;
            break;
        }
    }
    
    if (category == '')
        return;
    
    db.CriteriaLevel3.update({_id: item.Id}, { $set: { Category: category }}, { upsert: false, multiple: false})
});


db.CriteriaLevel3.update({Name: { $in: ["Total ESG Score","Environment Score","Social Score","Governance Score","Preparedness Score","Disclosure Score","Quantitative Performance Score"]}}, { $set: { Category: "Score"}}, { upsert: false, multi: true})
db.CriteriaLevel3.update({Name: { $in: ["Rank","Social Rank","Governance Rank","Environment Rank"]}}, { $set: { Category: "Rank"}}, { upsert: false, multi: true})
db.CriteriaLevel3.update({Name: { $in: ["Percentile", "Social Percentile", "Governance Percentile", "Environment Percentile"]}}, { $set: { Category: "Percentile"}}, { upsert: false, multi: true})
db.CriteriaLevel3.update({Name: { $in: ["Comparative Group Average", "Comparative Group Average Environment", "Comparative Group Average Social", "Comparative Group Average Governance"]}}, { $set: { Category: "Comparative"}}, { upsert: false, multi: true})
db.CriteriaLevel3.update({Name: { $in: ["SPL Code"]}}, { $set: { Category: "SPL Code"}}, { upsert: false, multi: true})
